package com.soo.hoo.admin.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.soo.hoo.admin.mapper.SysRoleMapper;
import com.soo.hoo.admin.model.entity.SysRole;
import com.soo.hoo.admin.service.RoleService;
import com.soo.hoo.core.exception.GlobalException;
import com.soo.hoo.core.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色管理服务
 * </p>
 *
 * @author 杨燚
 * @since 2023-04-11
 */
@Service
public class RoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements RoleService {

    @Override
    public void verifyRole(String roleName) {
        LambdaQueryWrapper<SysRole> lqw = new LambdaQueryWrapper<SysRole>()
                .eq(SysRole::getRoleName, roleName);
        List<SysRole> roles = baseMapper.selectList(lqw);
        if (CollUtil.isNotEmpty(roles)){
            throw new GlobalException("角色【"+roleName+"】已存在，");
        }
    }
}
